package com.fuqiang.quartz.demo1;

import com.fuqiang.quartz.job.HelloJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class Demo1 {
    public static void main(String[] args) throws SchedulerException {
        /**
         * 对象 TriggerBuilder 启动任务时间
            startNow 立即启动
            startAt (Date) 指定时间启动
            对象 SimpleScheduleBuilder 进行简单任务重复执行
            repeatSecondly …() 多少秒后重复执行
            repeatminutely …() 多少分钟后重复执行
            repeatHourly …() 多少小时后重复执行
         */
        //定时器对象
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

        //定义一个工作对象
//        JobDetail jobDetail = JobBuilder.newJob(HelloJob.class).withIdentity("job1","gorup1").build();

        //定义触发器
        Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1","gorup1").startNow()
                .withSchedule(SimpleScheduleBuilder.repeatSecondlyForever(5)).build();

        //像日历一样执行定时任务
        /**
         * Trigger trigger = TriggerBuilder.newTrigger()
         .withIdentity("trigger1", "group1")
         .withSchedule(CronScheduleBuilder.cronSchedule("0 0 0 ? * *"))
         .build();

         */
//        scheduler.scheduleJob(jobDetail, trigger);

        //开启定时任务
//        scheduler.start();

        //关闭定时任务
//        scheduler.shutdown();
    }
}
